#!/bin/sh

set -e
set -x

if [ -z $WORKSPACE ]; then
    export WORKSPACE=`pwd`
fi

if [ -z $ANDROID_HOME ]; then
    if [ -e ~/.android/bashrc ]; then
        . ~/.android/bashrc
    else
        echo "ANDROID_HOME must be set!"
        exit
    fi
fi

export TZ=UTC
TIMESTAMP=`git log -n1 --format=format:%ai`

# reset version code/name to current date
versionCodeDate=`faketime "$TIMESTAMP" date +%s`
versionNameDate=`faketime "$TIMESTAMP" date +%Y-%m-%d_%H.%M.%S`

sed -i \
    -e "s,android:versionCode=\"[0-9][0-9]*\",android:versionCode=\"$versionCodeDate\"," \
    -e "s,android:versionName=\"\([^\"][^\"]*\)\",android:versionName=\"\1.$versionNameDate\"," \
    libnetcipher/AndroidManifest.xml

./setup-ant
